﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!doctype html>
<html ng-app="duo" lang="zh" class="no-js">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shenzhen Santiago Tech Co., Ltd.—— Duo</title>
<link href="images/favicon.ico" type="images/x-icon" rel="shortcut icon" />
<link 	rel="stylesheet" 	href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">
<link 	rel="stylesheet" 	href="css/normalize.css" />
<link 	rel="stylesheet" 	href="css/phonestyle.css" />
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/modernizr.js" ></script>
<script type="text/javascript" src="js/nav_animate.js" ></script>
<script>window.location.href='#/home_phone';</script>
</head>
<body  ng-controller="main" id="box">
	<div id="phone_nav">
		<span class="nav_logo">
			<img src="images/logo2.png"/>
		</span>
	
		<span id="click"><a href="#" class="nav_trigger" ><span class="nav_icon"></span></a></span>
		<nav class="nav" id="pop">
			<ul class="nav_list">
				<li  ng-repeat="nav in navList" ng-if="nav.level == 0" class="nav_item nav_item_url" ui-sref="{{nav.url}}"><a class="nav_link" >{{nav.name}}</a></li>
				<li  ng-repeat="nav in navList" ng-if="nav.level == 1" class="nav_item">
					<a class="nav_link_a nav_link">{{nav.name}}<span class="caret"></span></a>
					<ul ng-if="nav.level == 1" class="zi_nav_list">
						<li   ng-repeat="second in nav.child" class="nav_item nav_item_url zi_nav_li" ui-sref="{{second.url}}">						
							<a class="nav_link" >{{second.name}}</a>
						</li>
					</ul>
				</li>
			</ul>
		</nav>
	</div>


	<div ui-view=""></div>
	<div style="width: 100%;height: 50px;line-height: 50px;text-align: center;color:rgba(83,83,83);">
		Copyright © Earl&nbsp;Technology.All Rights Reserved
	</div>
	
	<script>
		// ———————— angular代码 START ————————


		var app = angular.module('duo', ["ui.router"]);
		// 路由，后台jsp动态生成
		app.config(function($stateProvider) {
		  $stateProvider
		   
		    <%
		  String[]ar=(String[])session.getAttribute("gg");
		  if(ar!=null){
		  for(int i=0; i <ar.length;i++){%> 
		    .state('<%=ar[i]%>', {
		      url: '/<%=ar[i]%>',
		      templateUrl: 'http://112.74.204.208/webapp/<%=ar[i]%>/index.html'
		    })
		    <%}%>
		    <%}%>

		  ;
		})

		app.directive('loadScript', function() { 
			return { 
			restrict: 'EA', 
			terminal: true, 
			link: function(scope, element, attr) { 
			if (attr.ngSrc) { 
			var s = document.createElement('script'); 
			s.src = attr.ngSrc; 
			document.body.appendChild(s); 
			} 
			} 
			}; 
		}); 

		app.controller('main', function($scope, $rootScope ,$state, $http) {
			// 此处地址换成对应接口地址
			$http.get("http://112.74.204.208/webapp/getAllMenu1")
		    .success(function (response) {

		    	var realData = response.allmenu;
				var navList = new Array();

				// 数据转换，将接口数据转换成标准数据
				for(var i=0;i<realData.length;i++){

					if(realData[i].child == null){
						// 如果没有二级导航，即为一级导航，例如首页
						var tempItem = {
							"name": realData[i].menu.menuName,
					    	 "level": 0,
					     	 "url": realData[i].menu.menuPhonechain,
					     	 "order": realData[i].menu.menuOrder,
					     	 "child": ""
						};
						navList.push(tempItem);

					}else{
						// 若有二级导航，则遍历二级导航
						var tempChildList = new Array();
						for(var x=0;x<realData[i].child.length;x++){
								var tempChildItem = {
								"name": realData[i].child[x].a.menuName,
						         "level": 2,
						         "url": realData[i].child[x].a.menuPhonechain,
						         "img": realData[i].child[x].a.menuPicture
							}
							tempChildList.push(tempChildItem);
						}
						tempChildList.sort(function(a,b){return a.order>b.order?1:-1});
						
						var tempItem = {
							"name": realData[i].menu.menuName,
					    	 "level": 1,
					     	 "url": realData[i].menu.menuChain,
					     	 "order": realData[i].menu.menuOrder,
					     	 "child": tempChildList
						};
						navList.push(tempItem);
						
					}
					navList.sort(function(a,b){return a.order>b.order?1:-1});
				}
				$scope.navList = navList;

		    })
		    .error(function(response){

		    	// 接口访问失败时（测试数据）［模拟用］
		    	// 0为无二级分类的一级分类 1为有二级分类的一级分类  2为二级分类
		    	var data ={
					  "allmenu": [
					    {
					      "menu": {
					        "menu": null,
					        "menuChain": "aaa",
					        "menuId": 224,
					        "menuName": "一级菜单1",
					        "menuPhonechain": "aaa",
					        "menuPicture": "webapp/photo/94.7350136327216712906030_124355855000_2.png",
					        "menuOrder": 3,
					        "menus": []
					      },
					      "child": [
					        {
					          "a": {
					            "menu": null,
					            "menuChain": "aaa",
					            "menuId": 226,
					            "menuName": "二级菜单1",
					            "menuPhonechain": "aaa",
					            "menuPicture": "webapp/photo/94.7350136327216712906030_124355855000_2.png",
					            "menuOrder": 1,
					            "menus": []
					          }
					        },
					        {
					          "a": {
					            "menu": null,
					            "menuChain": "aaa",
					            "menuId": 227,
					            "menuName": "二级菜单2",
					            "menuPhonechain": "aaa",
					            "menuPicture": "webapp/photo/2.294188944240660412906030_124355855000_2.png",
					            "menuOrder": 2,
					            "menus": []
					          }
					        }
					      ]
					    },
					    {
					      "menu": {
					        "menu": null,
					        "menuChain": "aaa",
					        "menuId": 228,
					        "menuName": "一级菜单2",
					        "menuPhonechain": "aaa",
					        "menuPicture": "webapp/photo/2.294188944240660412906030_124355855000_2.png",
					        "menuOrder": 2,
					        "menus": []
					      }
					    }
					  ]
					};
				var realData = data.allmenu;
				var navList = new Array();

				// 数据转换，将接口数据转换成标准数据
				for(var i=0;i<realData.length;i++){

					if(realData[i].child == null){
						// 如果没有二级导航，即为一级导航，例如首页
						var tempItem = {
							"name": realData[i].menu.menuName,
					    	 "level": 0,
					     	 "url": realData[i].menu.menuPhonechain,
					     	 "order": realData[i].menu.menuOrder,
					     	 "child": ""
						};
						navList.push(tempItem);

					}else{
						// 若有二级导航，则遍历二级导航
						var tempChildList = new Array();
						for(var x=0;x<realData[i].child.length;x++){
								var tempChildItem = {
								"name": realData[i].child[x].a.menuName,
						         "level": 2,
						         "url": realData[i].child[x].a.menuPhonechain,
						         "img": realData[i].child[x].a.menuPicture
							}
							tempChildList.push(tempChildItem);
						}
						tempChildList.sort(function(a,b){return a.order>b.order?1:-1});

						var tempItem = {
							"name": realData[i].menu.menuName,
					    	 "level": 1,
					     	 "url": realData[i].menu.menuPhonechain,
					     	 "order": realData[i].menu.menuOrder,
					     	 "child": tempChildList
						};
						navList.push(tempItem);
						
					}
					navList.sort(function(a,b){return a.order>b.order?1:-1});
				}
				$scope.navList = navList;
				
		    });
		})
		// ———————— angular代码 END ————————

	</script>
</body>
</html>